 
<template>
	<view class="page"> 
		<view class="live-camera">
			<view class="preview">				
				<image :src="resultUrl?resultUrl:path" mode="widthFix"></image>  
			</view>
			 
			<view class="bottom">	
				<template v-if="!resultUrl">
					<view class="cancle" @click="cancle">
						<image src="@/static/images/close_icon_1.png" mode="widthFix"></image>
					</view> 
					<view class="save" @click="save"><image src="@/static/images/save_icon.png" mode="widthFix"></image></view> 
				</template>
				
				<template v-else>
					<navigator url="/package_shibie/dataList/dataList" hover-class="none" class="link">历史识别</navigator> 
					<view class="link" @click="cancle">继续拍照</view> 
				</template>
				
			</view> 
		</view>	
	</view>
</template>
 
<script>
import { 
		uploadImage, 
		uploadToServe 
	} from '@/common/util.js'
export default {
	data() {
		return { 
			path:'', 
			systemInfo:{},
			userInfo:uni.getStorageSync('userInfo'),
			resultUrl:''
		};
	},
	async onLoad(params) {  
		this.path=params.path; 
		 
	},
	async onShow() { 
	},
	methods: {
		
		// 获取手机系统信息
		async getSystemInfo() {
			//处理安卓手机异步授权问题 
			let res = await getSystemInfo();
			return res 
		},  
		
 		
		save: async function() {
			// 上传现场照片
			let _this = this; 
			uni.showLoading({
				mask:true,
				title:'照片上传中'
			})
			let params_data = {};
			params_data.status = 0;
			params_data.url = this.path;
			uploadToServe({
				url: '/yfk/upload-file',
				filePath: this.path,
				name: 'photo',
				formData: {
					'p_id': 0,
					'uid': _this.userInfo.id
				}
			}).then((up_res) => {    
				if (up_res.ret == 0) {	
					uni.hideLoading();
					params_data.file_name = up_res.data.file_name;
					params_data.file_path = up_res.data.file_path;
					params_data.file_type = up_res.data.file_type;
					params_data.status = up_res.data.status;
					params_data.type = up_res.data.type; 	
					 
					let files_data=JSON.stringify(params_data);
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
						_this.$store.commit('CERTIFICATEPHOTO_UPDATE',files_data)
						// uni.redirectTo({
						// 	url:'/package_member/addCertificateform/addCertificateform?type=edit&files='+files_data
						// })
					},500)
					
				}
			}).catch((err)=>{ 
			}) 
			
			// uploadToServe({
			// 	type:1,
			// 	url: 'https://shibie.honghuoyi.com/user/sb-insert.do', 
			// 	filePath: this.path,
			// 	name: 'myfile',
			// 	formData:{
			// 		appid:100002,
			// 		token:res.data.data.token,
			// 		uid:this.userInfo.id
			// 	}
			// }).then((up_res) => { 
			// 	console.log(up_res)
			// 	uni.hideLoading();
			// 	if (up_res.ret == 1000) {	
			// 		this.resultUrl='https://shibie.honghuoyi.com/image/sb-image.do?path='+up_res.data;
			// 		console.log(this.resultUrl)
			// 	}
			// }) 
		},
		 
		
		cancle:function(){
			uni.redirectTo({
				url:'/package_member/certificateCamera/certificateCamera'
			})
		},
		
		// save:function(){
		// 	console.log(123)
		// 	uni.navigateBack({
		// 		delta:1
		// 	})
		// },
		
	}
};
</script> 
<style lang="scss">
	.page{
		height: 100%;
	}
.live-camera {
	height: 100%; 
	.preview {
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;
		z-index: 1;
		width: 100%;
		height: calc(100% - 90px); 	 
		image{
			width: 100%;
		}
	}
	#cutImage{
		position: absolute;
		left:0;
		top:0; 
		width: 100%;
		height: 100%; 
		background: #f00;
	}
	.bottom {
		position: absolute;
		left: 0;
		bottom: 0;
		width: 80%;
		padding:0 10%;
		height: 90px;
		z-index: 98;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #000;
		box-sizing:inherit;	
		.cancle,.save{
			width: 90rpx;
			height: 90rpx;
			display: flex;
			align-items: center;
			justify-content: center; 
		}
		.cancle {			 
			color:#fff;
			font-size: 34rpx; 
			image{
				width: 50%;
			}
		}
		.link{
			color:#fff;
			font-size: 34rpx; 
		}
		.save{
			image{
				width: 60%;
			}
		}
	}
} 
</style>